package com.scholarship;

import com.google.common.base.Charsets;
import com.google.common.hash.Funnel;
import com.scholarship.common.config.BloomFilterHelper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement
@EnableAsync
@SpringBootApplication
//注解扫描多个mapper包
@MapperScan("com.scholarship.modules.*.mapper")
public class ScholarshipServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ScholarshipServerApplication.class);
    }

    /**
     * 初始化布隆过滤器
     * @return
     */
    @Bean
    public BloomFilterHelper<String> initBloomFilterHelper() {
        //设置预计插入量为1000，可接收错误率为0.01
        return new BloomFilterHelper<>(
                (Funnel<String>) (from, into) -> into.putString(from, Charsets.UTF_8).putString(from, Charsets.UTF_8),
                1000, 0.01);
    }
}
